<!DOCTYPE html>




<html class="theme-next mist" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="python,jupyter," />








  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon-16x16-next.png?v=5.1.2" />






<meta name="description" content="在 centos 下配置 jupyter配置文档jupyter notebook –generate-config 生成默认配置文档 修改密码：1. windows下，打开命令行，重新生成一个jupyter配置文件： jupyter notebook --generate-config　2. 修个配置文件，找到这个新生成的文件： 123456789101112Windows: C:\Users\U">
<meta name="keywords" content="python,jupyter">
<meta property="og:type" content="article">
<meta property="og:title" content="python-jupyter-使用总结">
<meta property="og:url" content="http://xchcloud.cn/python-jupyter-使用总结/index.html">
<meta property="og:site_name" content="超哥记录日记">
<meta property="og:description" content="在 centos 下配置 jupyter配置文档jupyter notebook –generate-config 生成默认配置文档 修改密码：1. windows下，打开命令行，重新生成一个jupyter配置文件： jupyter notebook --generate-config　2. 修个配置文件，找到这个新生成的文件： 123456789101112Windows: C:\Users\U">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-08-02T15:05:08.778Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="python-jupyter-使用总结">
<meta name="twitter:description" content="在 centos 下配置 jupyter配置文档jupyter notebook –generate-config 生成默认配置文档 修改密码：1. windows下，打开命令行，重新生成一个jupyter配置文件： jupyter notebook --generate-config　2. 修个配置文件，找到这个新生成的文件： 123456789101112Windows: C:\Users\U">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: false,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://xchcloud.cn/python-jupyter-使用总结/"/>





  <title>python-jupyter-使用总结 | 超哥记录日记</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b8d23512908ca3b4b175b2620a75740f";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">超哥记录日记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">生命有息、学无止境、折腾不止</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://xchcloud.cn/python-jupyter-使用总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="John Doe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://tuchuang-xchcloud-1253428588.cos.ap-chengdu.myqcloud.com/blog/header.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="超哥记录日记">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">python-jupyter-使用总结</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-04-12T09:50:22+08:00">
                2019-04-12
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index">
                    <span itemprop="name">python</span>
                  </a>
                </span>

                
                
              
            </span>
          

 


          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o">访问数</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>°C
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  2,742
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  11
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="在-centos-下配置-jupyter"><a href="#在-centos-下配置-jupyter" class="headerlink" title="在 centos 下配置 jupyter"></a>在 centos 下配置 jupyter</h2><h3 id="配置文档"><a href="#配置文档" class="headerlink" title="配置文档"></a>配置文档</h3><p>jupyter notebook –generate-config 生成默认配置文档</p>
<h3 id="修改密码："><a href="#修改密码：" class="headerlink" title="修改密码："></a>修改密码：</h3><p><strong>1.</strong> windows下，打开命令行，重新生成一个jupyter配置文件：</p>
<p><code>jupyter notebook --generate-config</code><br>　<br><strong>2.</strong> 修个配置文件，找到这个新生成的文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Windows: </span><br><span class="line"></span><br><span class="line">C:\Users\USERNAME\.jupyter\jupyter_notebook_config.py</span><br><span class="line"></span><br><span class="line">linux :</span><br><span class="line">vim /root/.jupyter/jupyter_notebook_config.py</span><br><span class="line"></span><br><span class="line">搜索 NotebookApp.allow_password_change，改为：</span><br><span class="line"></span><br><span class="line">NotebookApp.allow_password_change=False ，记得去掉注释的#</span><br><span class="line"></span><br><span class="line">也不要搜索了，麻烦，直接再第一行加</span><br></pre></td></tr></table></figure>
<p><strong>3.</strong> 回到命令行，运行jupyter notebook password<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">notebook password</span><br><span class="line">Enter password:             #键入密码，不显示的</span><br><span class="line">Verify password:            #再次重复键入密码</span><br><span class="line">[NotebookPasswordApp] Wrote hashed password to C:\Users\用户\.jupyter\jupyter_notebook_config.json     #密码生成的一串sha1，写入到了这个文件，等下要把这串sha1，复制到第一个生成的配置文件中</span><br></pre></td></tr></table></figure></p>
<p><strong>4.</strong> 还差一步密码才可以生效使用，在第一个jupyter_notebook_config.py配置文件中找到<br>“c.NotebookApp.password“，等于，刚生成的那个密码sha1，效果如下：去掉前面的”#“</p>
<p><code>c.NotebookApp.password = u&#39;sha1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&#39;</code></p>
<p><strong>5.</strong> 保险起见，把jupyter重启，之后，无论是更换浏览器还是Logout登陆，新密码都可以正常使用了。</p>
<h3 id="访问是https"><a href="#访问是https" class="headerlink" title="访问是https"></a>访问是https</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">问题：Jupyter notebook 远程server打开时遇到 socket.gaierror: [Errno -2] Name or service not known</span><br><span class="line"></span><br><span class="line">这个问题主要是由于远程打开的时候，并没有allow_remote_access=True</span><br></pre></td></tr></table></figure>
<p>反向代理设置问题</p>
<p>修改(直接在前几行添加）：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">c.NotebookApp.ip=&apos;*&apos; # 允许所有ip访问</span><br></pre></td></tr></table></figure></p>
<p><strong>踩坑：</strong> 设置了反向代理，访问什么的没问题，但是链接不到解释服务器，打不开终端，各种修改无果！修改允许所有IP访问，然后设置301重定向，近似完美解决。</p>
<h3 id="修改Jupyter工作目录"><a href="#修改Jupyter工作目录" class="headerlink" title="修改Jupyter工作目录"></a>修改Jupyter工作目录</h3><p><code>c.NotebookApp.notebook_dir = &#39;想设置哪个就是哪个&#39;</code></p>
<h3 id="启动命令："><a href="#启动命令：" class="headerlink" title="启动命令："></a>启动命令：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jupyter notebook --config /root/.jupyter/jupyter_notebook_config.py --allow-root</span><br></pre></td></tr></table></figure>
<p>启动以后，还可以给Python环境安装包之类。如果希望Jupyter长久运行，可以使用nohup后台运行。</p>
<h2 id="杀死占用端口程序进程"><a href="#杀死占用端口程序进程" class="headerlink" title="杀死占用端口程序进程"></a>杀死占用端口程序进程</h2><p>根据端口查看这个进程的pid<br>netstat -lnp|grep 8080   #8080请换为你的apache需要的端口<br>查看进程的详细信息<br>ps 1777    #1777就是上一步得到的pid<br>杀掉进程<br>例如： kill -9 [PID]  #-9 表示强迫进程立即停止</p>
<p><a href="https://www.cnblogs.com/coder-lzh/p/8977232.html" target="_blank" rel="noopener">参考地址</a></p>
<h2 id="修改jupyter的权限"><a href="#修改jupyter的权限" class="headerlink" title="修改jupyter的权限"></a>修改jupyter的权限</h2><p>当我们用命令行在浏览器中启动jupyter notebook后需要点击右上角的New创建新的python文件，此时会报错。在Linux下可以用命令行解决这个问题。首先需要找到anaconda2中jupyter文件，在anaconda2中的share文件中，对jupyter执行如下命令，来修改jupyter的权限：</p>
<p><code>chmod +777 /root/.jupyter/practice</code></p>
<p>之后重启jupyter即可运行,python代码</p>
<h2 id="jupyter-快捷键"><a href="#jupyter-快捷键" class="headerlink" title="jupyter 快捷键"></a>jupyter 快捷键</h2><p><a href="https://blog.csdn.net/HeatDeath/article/details/78030902" target="_blank" rel="noopener">Jupyter Notebook 快捷键</a></p>
<h2 id="jupyter-notebook-写代码自动补全"><a href="#jupyter-notebook-写代码自动补全" class="headerlink" title="jupyter notebook 写代码自动补全"></a>jupyter notebook 写代码自动补全</h2><p>1.安装nbextensions<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pip install jupyter_contrib_nbextensions -i https://pypi.mirrors.ustc.edu.cn/simple</span><br><span class="line">jupyter contrib nbextension install --user</span><br></pre></td></tr></table></figure></p>
<p>2.安装nbextensions_configurator<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pip install --user jupyter_nbextensions_configurator </span><br><span class="line">jupyter nbextensions_configurator enable --user</span><br></pre></td></tr></table></figure></p>
<p>如果提示缺少依赖，就使用pip安装对应依赖即可。</p>
<p>重启jupyter，在弹出的主页面里，能看到增加了一个Nbextensions标签页，在这个页面里，勾选Hinterland即启用了代码自动补全,然后重启大功告成。</p>
<p><a href="https://blog.csdn.net/weixin_33671935/article/details/85181176?tdsourcetag=s_pctim_aiomsg" target="_blank" rel="noopener">Jupyter Notebook 超实用的 5 个插件</a></p>
<h3 id="出现的问题"><a href="#出现的问题" class="headerlink" title="出现的问题"></a>出现的问题</h3><p>如果出现错误如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Installing collected packages: msgpack</span><br><span class="line">Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。:</span><br><span class="line">&apos;E:\\JiangHeSong\\Anaconda35.2.0\\Lib\\site-packages\\msgpack\\_packer.cp36-win_</span><br><span class="line">amd64.pyd&apos;</span><br><span class="line">Consider using the `--user` option or check the permissions.</span><br><span class="line"> </span><br><span class="line">You are using pip version 10.0.1, however version 18.0 is available.</span><br><span class="line">You should consider upgrading via the &apos;python -m pip install --upgrade pip&apos; comm</span><br><span class="line">and.</span><br></pre></td></tr></table></figure></p>
<p>只需要加一个–user 例如：</p>
<p><code>pip install --user msgpack -i https://pypi.mirrors.ustc.edu.cn/simple</code></p>
<h2 id="在Jupyter-Notebook中交互式运行C-代码"><a href="#在Jupyter-Notebook中交互式运行C-代码" class="headerlink" title="在Jupyter Notebook中交互式运行C++代码"></a>在Jupyter Notebook中交互式运行C++代码</h2><h3 id="编译安装（坑货）"><a href="#编译安装（坑货）" class="headerlink" title="编译安装（坑货）"></a>编译安装（坑货）</h3><p>参考：为什么是坑货呢？<a href="http://blog.sina.cn/dpool/blog/s/blog_541944e10102xla0.html" target="_blank" rel="noopener">Jupyternotebook添加c++核心支持的配置过程(新浪blog)</a></p>
<p>Jupyter Notebook 支持非常多的编程语言，而且可以直接运行这些语言的代码。要让 Jupyter Notebook 能够运行特定语言的代码，需要添加对应的内核。具体支持的语言及内核可以查看该链接： <a href="https://github.com/jupyter/jupyter/wiki/Jupyter-kernels" target="_blank" rel="noopener">https://github.com/jupyter/jupyter/wiki/Jupyter-kernels</a> 。</p>
<p>cling 内核依赖于 Python3</p>
<p>添加 C++ cling 内核</p>
<p>克隆 cling 的 Github 官方仓库：</p>
<p><code>git clone https://github.com/root-project/cling.git</code></p>
<p>在进行编译操作之前，首先要确保你的机器上已经装好了 cmake 工具，即能够直接通过输入命令 cmake<br>执行程序。</p>
<p>如果 cmake<br>已经正确安装，就可以进行以下的操作了。</p>
<p>切换到 cling/tools/packaging/ 目录下，执行以下两条命令：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">chmod +x cpt.py  </span><br><span class="line">./cpt.py --check-requirements &amp;&amp; ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/</span><br></pre></td></tr></table></figure></p>
<p>这个过程包含了从网络上获取源文件以及编译，是最为耗时的一个阶段，以小时计。</p>
<p>编译完成后，需要在 python3 中安装 clingkernel。切换到 cling/tools/Jupyter/ 目录下，执行</p>
<p><code>pip3 install kernel/</code></p>
<p>最后一步，往 Jupyter Notebook 中添加 cling 内核，可以根据自己的需要安装特定 C++ 规范的 cling 内核，例如 cling-cpp11, cling-cpp14, cling-cpp17。</p>
<p><code>jupyter kernelspec install kernel/cling-cpp17</code></p>
<p>如果没有其他问题，此时就可以打开 Jupyter Notebook 感受不一样的 C++ 编程了！<br>官方代码示例<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">class Rectangle &#123;  </span><br><span class="line">    private:</span><br><span class="line">        double w;</span><br><span class="line">        double h;</span><br><span class="line"></span><br><span class="line">    public:</span><br><span class="line"></span><br><span class="line">        Rectangle(double w_, double h_) &#123;</span><br><span class="line">            w = w_;</span><br><span class="line">            h = h_;</span><br><span class="line">        &#125;</span><br><span class="line">        double area(void) &#123;</span><br><span class="line">            return w * h;</span><br><span class="line">        &#125;</span><br><span class="line">        double perimiter(void) &#123;</span><br><span class="line">            return 2 * (w + h);</span><br><span class="line">        &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">Rectangle r = Rectangle(5, 4); </span><br><span class="line">r.area();</span><br></pre></td></tr></table></figure></p>
<p>输出为：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cpp</span><br><span class="line">(double) 20.000000</span><br></pre></td></tr></table></figure></p>
<h3 id="快速安装"><a href="#快速安装" class="headerlink" title="快速安装"></a>快速安装</h3><p>一、 安装Xeus-Cling</p>
<p>目前已支持Mac和Ubuntu，windows自测，推荐使用conda安装。</p>
<p>1.首先创建一个conda environment并激活(如果不会在虚拟环境中打开jupyter,可在base环境中安装）<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">conda create -n Xeus-Cling</span><br><span class="line">source activate Xeus-Cling</span><br></pre></td></tr></table></figure></p>
<p>然后使用conda package installer安装Xeus-Cling</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda install -c conda-forge xeus-cling</span><br></pre></td></tr></table></figure>
<p>完成！<br>二、测试C++ Kernel</p>
<p>1.首先，激活环境并打开jupyter-notebook<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">source activate Xeus-Cling</span><br><span class="line">jupyter-notebook</span><br></pre></td></tr></table></figure></p>
<h3 id="安装的-C-内核-11-14-17-区别"><a href="#安装的-C-内核-11-14-17-区别" class="headerlink" title="安装的 C++ 内核 11 14 17 区别"></a>安装的 C++ 内核 11 14 17 区别</h3><p><a href="https://blog.csdn.net/xiaomu_347/article/details/82563688" target="_blank" rel="noopener">c++11/14/17标准你了解多少(CSDN)</a><br><a href="https://docs.microsoft.com/en-us/previous-versions/hh567368(v=vs.140" target="_blank" rel="noopener">官方(微软、英语)</a>#featurelist)</p>
<h2 id="Conda使用手册"><a href="#Conda使用手册" class="headerlink" title="Conda使用手册"></a>Conda使用手册</h2><p><a href="https://blog.csdn.net/chenfeidi1/article/details/80873993" target="_blank" rel="noopener">Conda使用手册(CSDN)</a></p>
<p><a href="https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/" target="_blank" rel="noopener">清华大学开源软件镜像站</a></p>
<p><a href="https://mirrors.ustc.edu.cn/help/anaconda.html" target="_blank" rel="noopener">科大源镜像站</a></p>
<h2 id="jupyter-云平台"><a href="#jupyter-云平台" class="headerlink" title="jupyter 云平台"></a>jupyter 云平台</h2><p><a href="https://mybinder.org" target="_blank" rel="noopener">binder</a></p>
<p><a href="https://mybinder.org/v2/gh/QuantStack/xeus-cling/stable?filepath=notebooks/xcpp.ipynb&amp;tdsourcetag=s_pctim_aiomsg" target="_blank" rel="noopener">C++ jupyter</a></p>
<h2 id="只下载github的某个文件夹"><a href="#只下载github的某个文件夹" class="headerlink" title="只下载github的某个文件夹"></a>只下载github的某个文件夹</h2><p>很多时候我们只想下载某个文件夹，而不是整个目录</p>
<p>我们可以用svn，先安装<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">apt install subversion</span><br><span class="line"></span><br><span class="line">yum install subversion</span><br></pre></td></tr></table></figure></p>
<p>比如你要下载这个<a href="https://github.com/QuantStack/xeus-cling/tree/master/notebooks，将/tree/master/换成/trunk/即可" target="_blank" rel="noopener">https://github.com/QuantStack/xeus-cling/tree/master/notebooks，将/tree/master/换成/trunk/即可</a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">svn checkout https://github.com/QuantStack/xeus-cling/trunk/notebooks</span><br></pre></td></tr></table></figure></p>
<h2 id="奇技淫巧"><a href="#奇技淫巧" class="headerlink" title="奇技淫巧"></a>奇技淫巧</h2><p>1、Jupyter常用的快捷键</p>
<p>1）代码运行键</p>
<p>如需运行一个cell（代码框）内的Python代码，可以选择Ctrl + Enter组合键，也可以选择Shift + Enter组合键。两者的区别在于前者在运行完代码后不会新增cell，而后者会新增cell或跳转到下一个cell。</p>
<p>2）自动补齐键</p>
<p>在代码编写过程中，如果只记得函数或变量名称的前几个字母，可以通过Tab键，实现全名称（如函数名、方法名、变量名等）的自动补齐。</p>
<p>3）帮助查询键</p>
<p>Python中有庞大的第三方包，而每个包中又包含很多功能性的函数，在使用这些函数时，往往会忘记函数内参数的具体用法，此时可以在函数后面按入Shift+Tab组合键，查看对应的帮助文档，而且还可以多按几次“Tab”键，返回不同风格的帮助文档。</p>
<p>4）cell创建键</p>
<p>在command模式下，按下字母a键，则会在当前cell的上方新增一个cell，如果按下字母b键，则会在当前cell的下方新增一个cell。</p>
<p>5）cell删除键</p>
<p>在command模式下，连续按两次d字母键，就可以轻松删除当前cell。或者还有另一个方法，在command模式下，按一次字母x键也可以实现cell的删除。</p>
<p>6）注释添加/取消键</p>
<p>如需给代码行或代码块增加注释功能，可以使用“Ctrl+/”的组合键，对于代码块的注释需要先选中，在使用组合键。如果原始代码中没有注释符，按入该组合键则增加注释，否则将取消注释。</p>
<p>7）保存键</p>
<p>在编写代码时，最好养成良好的习惯，那就是编写代码便保存（尽管Jupyter默认会2分钟自动保存一次，但2分钟内万一出现一些意外，岂不是糟糕啦）。代码的保存可以在command模式下，按一次字母s键。</p>
<p>8）行号显示键</p>
<p>在其他编程环境中也许会显示代码行号，但是在Jupyter的默认情况下是没有代码行号的，如果期望一个cell中显示所有代码对于的行编号，可以在command模式下，按一次字母l键。</p>
<p>9）code与markdown间切换键</p>
<p>code指的是Jupyter环境下所进行的Python代码的编写，而markdown则是用于非代码的笔记内容的编写。两者之间是可以轻松切换的，在command模式下，按一次字母m便从code切换到markdowen模式；如果从command模式中，按一次字母y就可以从markdown模式切换到code模式。</p>
<p>2、Jupyter中的魔法函数</p>
<p>1）%pwd</p>
<p>该魔法函数用于显示Jupyter当前的工作空间。</p>
<p>2）%hist</p>
<p>该魔法函数用于显示当前Jupyter中，所有运行过的历史代码。</p>
<p>3）%who</p>
<p>该魔法函数用于显示当前Jupyter环境中的所有变量或名称。</p>
<p>4）%reset</p>
<p>该魔法函数用于删除当前Jupyter环境中的所有变量或名称。</p>
<p>5)%time</p>
<p>该魔法函数用于计算当前代码行的运行时长。</p>
<p>6)%timeit</p>
<p>该魔法函数用于计算当前代码行的平均运行时长（即在执行一个语句100000次(默认情况下)后，再给出运行最快3次的平均值。</p>
<p>7)%%timeit</p>
<p>该魔法函数用于计算当前cell的代码运行时长。</p>
<p>8）%matplotlib</p>
<p>该魔法函数用于显示绘图结果的风格，默认为%matplotlib inline，是直接将图片显示在浏览器中，如果希望图片单独生成，可以使用%matplotlib。</p>
<p>9）%load</p>
<p>该魔法函数用于加载本地Python文件或者网络中的Python文件，例如本地脚本文件的加载：%load xxx.py。</p>
<p>10）%run</p>
<p>该魔法函数用于运行本地或网络中的Python文件，例如本地脚本文件的运行：%load xxx.py。</p>
<h2 id="其他连接"><a href="#其他连接" class="headerlink" title="其他连接"></a>其他连接</h2><p><a href="http://url.cn/5xxEBSt" target="_blank" rel="noopener">jupyter notebook系列之 自定义主题、字体、字号等(WX)</a><br><a href="http://url.cn/5SelJCe" target="_blank" rel="noopener">python开发者必备，史上最详细的 jupyter 教程(WX)</a></p>
<p><a href="https://www.bilibili.com/read/cv1924277/" target="_blank" rel="noopener">在 jupyter 里使用 C++(B站文章)</a></p>
<p><a href="http://url.cn/52mfLFI" target="_blank" rel="noopener">Jupyter Notebook界面也可以如此炫酷？有人把Notebook玩出了新花样</a></p>
<p><a href="http://url.cn/5C4F90n" target="_blank" rel="noopener">十大至简规则！</a></p>

      
    </div>
    
    
    

      <div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

  
</div>

<div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/python-jupyter-使用总结/">python-jupyter-使用总结</a></p>
  <p><span>文章作者:</span></a>Chao</p>
  <p><span>发布时间:</span>2019年04月12日 - 09:04</p>
  <p><span>最后更新:</span>2019年08月02日 - 23:08</p>
  <p><span>原始链接:</span><a href="/python-jupyter-使用总结/" title="python-jupyter-使用总结">http://xchcloud.cn/python-jupyter-使用总结/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="http://xchcloud.cn/python-jupyter-使用总结/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
      $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
        });
    });  
</script>

      
</div>

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/python/" <i class="fa fa-tag"></i> python</a>
          
            <a href="/tags/jupyter/" <i class="fa fa-tag"></i> jupyter</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/python-Django-HFNU-Small-Size网站设计/" rel="next" title="python-Django-HFNU_Small_Size网站设计">
                <i class="fa fa-chevron-left"></i> python-Django-HFNU_Small_Size网站设计
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/Lua-查缺补漏/" rel="prev" title="Lua-查缺补漏">
                Lua-查缺补漏 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://tuchuang-xchcloud-1253428588.cos.ap-chengdu.myqcloud.com/blog/header.jpg"
               alt="John Doe" />
          </span></a>Chao</p>


           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">60</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">33</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">65</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/lhc0101" target="_blank" title="Github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                    
                      Github
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=qJmcmp_akJ6ZmZHo2dmGy8fF" target="_blank" title="E-mail">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                    
                      E-mail
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              dalao&nbsp;
              <i class="fa  fa-fw fa-globe"></i>
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://giracle.cn" title="DJG" target="_blank">DJG</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://owencxc.github.io" title="CX" target="_blank">CX</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.myzwl.win" title="ZWL" target="_blank">ZWL</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wuliekun.me/" title="WLK" target="_blank">WLK</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://Li-rr.github.io" title="LRR" target="_blank">LRR</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://dh.xchcloud.cn" title="导航" target="_blank">导航</a>
                </li>
              
            </ul>
+        <div id="days"></div>
</script>
<script language="javascript">
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("06/26/2018 12:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>

          </div>
         

-        <div id="days"></div>
</script>
<script language="javascript">
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("06/26/2018 12:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#在-centos-下配置-jupyter"><span class="nav-number">1.</span> <span class="nav-text">在 centos 下配置 jupyter</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置文档"><span class="nav-number">1.1.</span> <span class="nav-text">配置文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改密码："><span class="nav-number">1.2.</span> <span class="nav-text">修改密码：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#访问是https"><span class="nav-number">1.3.</span> <span class="nav-text">访问是https</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改Jupyter工作目录"><span class="nav-number">1.4.</span> <span class="nav-text">修改Jupyter工作目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动命令："><span class="nav-number">1.5.</span> <span class="nav-text">启动命令：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#杀死占用端口程序进程"><span class="nav-number">2.</span> <span class="nav-text">杀死占用端口程序进程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改jupyter的权限"><span class="nav-number">3.</span> <span class="nav-text">修改jupyter的权限</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jupyter-快捷键"><span class="nav-number">4.</span> <span class="nav-text">jupyter 快捷键</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jupyter-notebook-写代码自动补全"><span class="nav-number">5.</span> <span class="nav-text">jupyter notebook 写代码自动补全</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#出现的问题"><span class="nav-number">5.1.</span> <span class="nav-text">出现的问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#在Jupyter-Notebook中交互式运行C-代码"><span class="nav-number">6.</span> <span class="nav-text">在Jupyter Notebook中交互式运行C++代码</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#编译安装（坑货）"><span class="nav-number">6.1.</span> <span class="nav-text">编译安装（坑货）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#快速安装"><span class="nav-number">6.2.</span> <span class="nav-text">快速安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装的-C-内核-11-14-17-区别"><span class="nav-number">6.3.</span> <span class="nav-text">安装的 C++ 内核 11 14 17 区别</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Conda使用手册"><span class="nav-number">7.</span> <span class="nav-text">Conda使用手册</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jupyter-云平台"><span class="nav-number">8.</span> <span class="nav-text">jupyter 云平台</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#只下载github的某个文件夹"><span class="nav-number">9.</span> <span class="nav-text">只下载github的某个文件夹</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#奇技淫巧"><span class="nav-number">10.</span> <span class="nav-text">奇技淫巧</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他连接"><span class="nav-number">11.</span> <span class="nav-text">其他连接</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Chao</span>
</div>



<div class="theme-info">
  <span class="post-count">博客全站共118.7k字</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">访客数</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">访客总量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>


        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  









  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/three/three.min.js"></script>

  
  <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.2"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.2"></script>


  

  

</body>
</html>
